import db from "../models/index.js";
let manager = db.manager;
let managerDao = {};
//判断是否存在这个管理员
managerDao.isExisted = (_account) => {
    return manager.findOne({
        where: {
            _account
        },
        raw: true,
    });
};
//判断是否存在这个权限的管理员
managerDao.isExistedByRole = (_account, _role) => {
    return manager.findOne({
        where: {
            _account,
            _role
        },
        raw: true,
    });
};
//判断管理员是存在且密码正确
managerDao.isExistedByPassword = (_account, _password) => {
    return manager.findOne({
        where: {
            _account,
            _password
        },
        raw: true,
    });
};
//获取管理员权限
managerDao.getManagerRole = (_account) => {
    return manager.findAndCountAll({
        attributes:['_role'],
        where: {
            _account
        },
        raw: true,
    });
};
managerDao.addManager = (_account, _passwordMd5, _role=0, t) => {
    if(!t) {
        return manager.create({_account, _passwordMd5, _role});
    }
    return manager.create({_account, _passwordMd5, _role}, {transaction:t});
};
export default managerDao;
